<?php
namespace Home\Controller;
use Think\Controller;
class ConditionController extends Controller {
    public function index(){
    	$this->display();
    }
    public function getConditionList(){
    	$res = D('condition')->getConditionList();
    	if(!$res){
    		return ajaxReturn(0,'获取失败');
    	}
    	return ajaxReturn(1,'获取成功',$res);
    }
    public function insert(){
    	$res = D('compare')->getCompareList();
    	$this->assign('compare',$res);
    	$this->display();
    }
    public function insertConditionInfo(){
    	if(!isset($_POST['condition_name']) || !$_POST['condition_name']){
    		return ajaxReturn(0,'传参失败');
    	}
    	$res = D('condition')->insertConditionInfo($_POST);
    	if(!$res){
    		return ajaxReturn(0,'添加失败');
    	}
    	return ajaxReturn(1,'添加成功');
    }
    public function revise(){
    	if(!isset($_GET['condition_id']) || !$_GET['condition_id']){
    		return ajaxReturn(0,'传参失败');
    	}
    	$res = D('condition')->getConditionInfo($_GET);
    	if(!$res){
    		return ajaxReturn(0,'添加失败');
    	}
    	$this->assign('condition',$res);
    	$res = D('compare')->getCompareList();
    	$this->assign('compare',$res);
    	$this->display();
    }
    public function reviseConditionInfo(){
    	if(!isset($_POST) || !$_POST){
    		return ajaxReturn(0,'传参失败');
    	}
    	$cond['condition_id'] = $_POST['condition_id'];
    	$res = D('condition')->reviseConditionInfo($cond,$_POST);
    	if($res === false){
    		return ajaxReturn(0,'修改失败');
    	}
    	return ajaxReturn(1,'修改成功');
    }
}